package com.weibo.survey.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.weibo.survey.dao.BaseDao;
import com.weibo.survey.domain.Page;
import com.weibo.survey.service.PageService;

@Service("pageService")
public class PageServiceImpl extends BaseServiceImpl<Page> implements PageService {

	@Resource(name = "pageDao")
	public void setBaseDao(BaseDao<Page> baseDao) {
		super.setBaseDao(baseDao);
	}

	@Override
	public Page getPageWithChildren(int id) {
		Page page = getEntity(id);
		page.getQuestions().size();
		return page;
	}

	@Override
	public void deletePage(int id) {
		//1.删除问题
		String hql="delete from Answer a where a.questionId in (select q.id from Question q where q.page.id=?)";
		baseDao.batchByHql(hql, id);
		//2.删问题
		hql="delete from Question q where q.page.id=?";
		baseDao.batchByHql(hql, id);
		//3.删页面
		hql="delete from Page p where p.id=?";
		baseDao.batchByHql(hql, id);
	}

}
